
COMMON_OBJ = minicore.o malloc.o showmsg.o strlib.o utils.o des.o grfio.o utf8.o miniassistant.o crashdump.o cryptopp.o
COMMON_DIR_OBJ = $(COMMON_OBJ:%=../common/obj/%)
COMMON_H = $(shell ls ../common/*.hpp)
COMMON_INCLUDE = -I../common/

LIBCONFIG_H = $(shell ls ../../3rdparty/libconfig/*.h)
LIBCONFIG_AR = ../../3rdparty/libconfig/obj/libconfig.a
LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig

YAML_CPP_OBJ = $(shell find ../../3rdparty/yaml-cpp/ -type f -name "*.cpp" | sed -e "s/\.cpp/\.o/g" )
YAML_CPP_DIR_OBJ = $(YAML_CPP_OBJ:%=obj/%)
YAML_CPP_AR = ../../3rdparty/yaml-cpp/obj/yaml-cpp.a
YAML_CPP_H = $(shell find ../../3rdparty/yaml-cpp/ -type f -name "*.h")
YAML_CPP_INCLUDE = -I../../3rdparty/yaml-cpp/include

# 以下内容添加自 PandasWS 开发团队
BREAKPAD_H = $(shell find ../../3rdparty/breakpad/ -type f -name "*.h")
BREAKPAD_AR = ../../3rdparty/breakpad/src/client/linux/libbreakpad_client.a
BREAKPAD_INCLUDE = -I../../3rdparty/breakpad/src

CRYPTOPP_H = $(shell find ../../3rdparty/cryptopp/ -type f -name "*.h")
CRYPTOPP_AR = ../../3rdparty/cryptopp/libcryptopp.a
CRYPTOPP_INCLUDE = -I../../3rdparty/cryptopp
# 以上内容添加自 PandasWS 开发团队

OTHER_H = ../config/renewal.hpp

MAPCACHE_OBJ = obj_all/mapcache.o

CSV2YAML_OBJ = obj_all/csv2yaml.o

@SET_MAKE@

#####################################################################
.PHONY : all mapcache csv2yaml clean help

all: mapcache csv2yaml

mapcache: obj_all $(MAPCACHE_OBJ) $(COMMON_DIR_OBJ) $(LIBCONFIG_OBJ) $(BREAKPAD_AR) $(CRYPTOPP_AR)
	@echo "	LD	$@"
	@@CXX@ @LDFLAGS@ -o ../../mapcache@EXEEXT@ $(MAPCACHE_OBJ) $(COMMON_DIR_OBJ) $(LIBCONFIG_AR) $(BREAKPAD_AR) $(CRYPTOPP_AR) @LIBS@

csv2yaml: obj_all $(CSV2YAML_OBJ) $(COMMON_DIR_OBJ) $(YAML_CPP_AR) $(BREAKPAD_AR) $(CRYPTOPP_AR)
	@echo "	LD	$@"
	@@CXX@ @LDFLAGS@ -o ../../csv2yaml@EXEEXT@ $(CSV2YAML_OBJ) $(COMMON_DIR_OBJ) $(YAML_CPP_AR) $(BREAKPAD_AR) $(CRYPTOPP_AR) @LIBS@

clean:
	@echo "	CLEAN	tool"
	@rm -rf obj_all/*.o ../../mapcache@EXEEXT@

help:
	@echo "possible targets are 'mapcache' 'all' 'clean' 'help'"
	@echo "'mapcache'  - mapcache generator"
	@echo "'csv2yaml'  - csv2yaml converter"
	@echo "'all'       - builds all above targets"
	@echo "'clean'     - cleans builds and objects"
	@echo "'help'      - outputs this message"

#####################################################################

obj_all:
	@-mkdir obj_all

obj_all/%.o: %.cpp $(COMMON_H) $(OTHER_H) $(LIBCONFIG_H) $(YAML_CPP_H) $(BREAKPAD_H) $(CRYPTOPP_H)
	@echo "	CXX	$<"
	@@CXX@ @CXXFLAGS@ $(COMMON_INCLUDE) $(LIBCONFIG_INCLUDE) $(YAML_CPP_INCLUDE) $(BREAKPAD_INCLUDE) $(CRYPTOPP_INCLUDE) @CPPFLAGS@ -c $(OUTPUT_OPTION) $<

# missing common object files
$(COMMON_DIR_OBJ):
	@$(MAKE) -C ../common server

$(LIBCONFIG_AR):
	@$(MAKE) -C ../../3rdparty/libconfig

$(YAML_CPP_AR):
	@$(MAKE) -C ../../3rdparty/yaml-cpp

# 以下内容添加自 PandasWS 开发团队
$(BREAKPAD_AR):
	@$(MAKE) -C ../../3rdparty/breakpad

$(CRYPTOPP_AR):
	@CXXFLAGS="-DNDEBUG @CXXFLAGS@" $(MAKE) -C ../../3rdparty/cryptopp libcryptopp.a
# 以上内容添加自 PandasWS 开发团队
